package com.example.study.basic.model;

import com.example.study.basic.exception.BasicCode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultModel {
    /**
     * 返回值描述
     */
    private String msg;
    /**
     * 返回数据
     */
    private Object data;
    /**
     * 状态码
     */
    private String code;

    public static ResultModel ok(Object data) {
        return new ResultModel(BasicCode.SUCCESS.msg, data, BasicCode.SUCCESS.code);
    }

    public static ResultModel fail(Object data) {
        return new ResultModel(BasicCode.STANDARD_ERROR.msg, data, BasicCode.STANDARD_ERROR.code);
    }

    public static ResultModel standard(String code, Object data, String msg) {
        return new ResultModel(msg, data, code);
    }

    @Override
    public String toString() {
        return "ResultModel{" +
                "msg='" + msg + '\'' +
                ", date=" + data +
                ", code='" + code + '\'' +
                '}';
    }
}
